#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define REP(i,n) for(int i=0;i<int(n);++i)
#define EACH(ep,pos) for(Edge *ep=head[pos];ep;ep=ep->next)
using namespace std;

typedef pair<int,int> pii;
struct Edge
{
	int vs,vt,cap;
	Edge *next;
};

Edge edge[5050*2];
Edge *head[5050];
int pri[5050],ei;
int ans[5050];
int n;
priority_queue<pii,vector<pii>,greater<pii> > q[5050];

void add(int vs,int vt,int cap)
{
	Edge et = { vs,vt,cap,head[vs] };
	edge[ei]=et;
	head[vs]=&edge[ei++];
}
void dfs(int pos,Edge *pre)
{
	int prev = pre->vs;
	//printf("dfs %d -> %d \n",prev,pos);
	REP(i,pre->cap)
	{
		if(q[pos].empty()) break;
		pii pt = q[pos].top(); q[pos].pop();
		//printf("(q[%d] size: %d) q[%d]push (%d) \n",pos,q[pos].size()+1,prev,pt.second);
		q[prev].push(pt);
	}
	EACH(ep,pos) if(ep->vt!=prev)
		dfs(ep->vt,ep);
}
int main()
{
	cin>>n;
	REP(i,n) cin>>pri[i+1],q[i+1].push(pii(pri[i+1],i+1));
	REP(i,n-1)
	{
		int vs,vt,cap;
		cin>>vs>>vt>>cap;
		add(vs,vt,cap);
		add(vt,vs,cap);
	}
	int cnt=0,day=0;
	while(true)
	{
		while(!q[1].empty())
		{
			pii tp=q[1].top(); q[1].pop();
			ans[tp.second]=day;
			//printf("day %d : %d \n",day,tp.second);
			cnt++;
		}
		if(cnt==n) break;
		EACH(ep,1)
			dfs(ep->vt,ep);
		day++;
	}
	REP(i,n) cout<<ans[i+1]<<" ";
	cout<<endl;
	return 0;
}
